; (completion-preview--try-table): Propagate extra properties.
authorEshel Yaron <me@eshelyaron.com>
Sun, 2 Mar 2025 07:03:04 +0000 (08:03 +0100)
committerEshel Yaron <me@eshelyaron.com>
Sun, 2 Mar 2025 07:14:35 +0000 (08:14 +0100)
* lisp/completion-preview.el
(completion-preview--try-table): Let-bind
'completion-extra-properties' to completion properties
that the completion backend (capf) provides, so that these
properties take effect when querying the completion table.
* test/lisp/completion-preview-tests.el
(completion-preview-propagates-properties): Add test.

lisp/completion-preview.el
test/lisp/completion-preview-tests.el

index 505cf45f48d030081a8047537e93ce0c6063068c..1c524985f055f4cbb82ff623ab6ba6f6e9204128 100644 (file)
@@ -293,6 +293,7 @@ candidates or if there are multiple matching completions and
   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   (let* ((pred (plist-get props :predicate))
          (string (buffer-substring beg end))
+         (completion-extra-properties props)
          (md (completion-metadata string table pred))
          (sort-fn (or (completion-metadata-get md 'cycle-sort-function)
                       (completion-metadata-get md 'display-sort-function)
index d76944920564d997bb7d8961d3d190f39571ac22..b8a45f00cb598ae037b4c8f91a58142bb0b768d2 100644 (file)
@@ -306,4 +306,17 @@ instead."
       (should exit-fn-called)
       (should (equal exit-fn-args '("foobar" finished))))))
 
+(ert-deftest completion-preview-propagates-properties ()
+  "Test the completion metadata handling of Completion Preview mode."
+  (with-temp-buffer
+    (setq-local
+     completion-preview-sort-function #'minibuffer-sort-alphabetically
+     completion-at-point-functions
+     (list (completion-preview-tests--capf '("foobaz" "foobar")
+                                           :display-sort-function #'identity)))
+    (insert "foo")
+    (let ((this-command 'self-insert-command))
+      (completion-preview--post-command))
+    (completion-preview-tests--check-preview "baz" 'completion-preview-common)))
+
 ;;; completion-preview-tests.el ends here